home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AmigActive 10
/
AACD 10.iso
/
AACD
/
Magazine
/
Online
/
httpproxy
/
goodies
/
proxyindex.rexx
< prev
Wrap
OS/2 REXX Batch file
|
1996-08-20
|
13KB
|
380 lines
/* proxyindex.rexx (0.63) 01-Aug-96
by mago@is-bremen.de
Written for httpproxy 0.14 alpha (30-Jul-96)
- Requirements: rexxtricks.library (Aminet), list, sort, type, echo, search
- Using this script without an argument, it creates three index files,
html sorted alpha. by time of file creation and an image page.
Plus an AmigaGuide file, wich enables you to delete single Proxy-files
by clicking on them (without warning). No Directorys are deleted.
- The file rexx:proxydel.rexx will be written. It's used by the guide-file.
- In an optional argument you can specify a searchpattern. All lines in
in the html and the images page containing this string are written into
{stem}g.html
- This script works only on the /http/ dir, so far.
*/
/********* config *********/
centdok = 0 /* center links or align left (bool) */
striport = 1 /* strip port numbers from URL's (bool) */
port = 80 /* port on wich your proxy is running */
fontsize = 3 /* Between 1 and 6 */
cachedir = 'data:cache/' /* With trailing slash! */
stem = 'data:cache' /* stem of the resulting files.
As there are:
{stem}.html the main page, only html
{stem}i.html the image page
{stem}ts.html all html pages sorted by time
{stem}g.html extract from both html pages
{stem}.guide to delete single cache entries */
/* If your LOCALE language is not German you may have to change this var */
monthident = 'Jan Feb Mär Apr Mai Jun Jul Aug Sep Okt Nov Dez'
/**************************/
address command;parse arg pat;numfiles=0;status=1
/*'copy amitcp:bin/httpfetch ram:'*/
'Resident >nil: c:list'
if fontsize > 1 then do;bs=fontsize;hs=bs-1;end
else do;bs=fontsize;hs=bs;end
if length(pat) > 0 then call grep
'echo >'stem'cache.cont'
if ~show('L','rexxtricks.library') then call addlib('rexxtricks.library',0,-30,0)
tcnt=0;cnt=0;icnt=0
fn.0 = 14
fn.1 = '/* 'stem'.guide */;address command;parse arg string'
fn.2 = 'if index(string,"@@") == 0 then "delete >nil: "string'
fn.3 = 'else'
fn.4 = 'do'
fn.5 = ' off=index(string,@@)'
fn.6 = ' roff=off'
fn.7 = ' do while off > 0'
fn.8 = ' roff=off'
fn.9 = ' off=index(string,@@,off+1)'
fn.10= ' end'
fn.11= ' str=string'
fn.12= ' str=delstr(insert("!",str,roff+1),roff,1)'
fn.13= ' "delete >nil: "string" "str'
fn.14= 'end'
if ~writefile('rexx:proxydel.rexx',fn) then call ferr('rexx:proxydel.rexx')
if ~open(tmp,'t:pi.tmp',w) then call ferr('t:pi.tmp')
if ~open(tmpt,'t:timeindex.tmp',w) then call ferr('t:timeindex.tmp')
if ~open(tmpx,'t:logx.tmp',w) then call ferr('t:logx.tmp')
if ~open(tmpg,'t:logg.tmp',w) then call ferr('t:logg.tmp')
if ~open(guide,stem'.guide',w) then call ferr(stem'.guide')
call writeln(guide,'@database "Httpproxy.guide"')
call writeln(guide,'@node main "Delete HttpProxy (0.14) Cache"')
call close(guide)
call htmlhead
call getcont /* Explore the cachedir */
call writech(stdout,' 'numfiles' ')
do i=1 to numfiles-1 /* Seperate files into page and image */
if index(upper(ofn.i),'.MOV') == 0 & index(upper(ofn.i),'.MPG') == 0 & index(upper(ofn.i),'NPH-COUNT') == 0 & index(upper(ofn.i),'.JPEG') == 0 & index(upper(ofn.i),'.GIF') == 0 & index(upper(ofn.i),'.JPG') == 0 then
do
call writeln tmp,'<a href="'ofn.i'">'str(ofn.i)'</a>'stat()'<br>'
call writeln tmpt,time.i' <a href="'ofn.i'">'str(ofn.i)'</a>'stat()'<br>'
trace off
cnt=cnt+1
end
else
do
call writeln tmpx,'<a href="'ofn.i'">'str(ofn.i)'</a>'stat()'<br>'
trace off
icnt=icnt+1
end
tcnt=tcnt+1
if tcnt == 101 then
do
tcnt=0
call writech(stdout,'*')
end
call writeln(tmpg,' @{ub}@{"'str(ofn.i)'" RX "rexx:proxydel.rexx 'ofp.i'"}@{ub}'stat())
trace off
end
call close(tmp);call close(tmpx);call close tmpg;call close tmpt;say
/* creation of the final files */
'Sort t:timeindex.tmp t:time.tmp'
call tsortpage
'Sort t:logg.tmp t:loge.tmp'
'Type >>'stem'.guide t:loge.tmp'
'Echo >>'stem'.guide @endnode'
'Sort t:pi.tmp t:log2.tmp';'Sort t:logx.tmp t:logy.tmp'
'Type >>'stem'.html t:log2.tmp'
if ~open(html,stem'.html',a) then call ferr(stem'.html')
call writeln(html,cenl(0)'<h/'bs'><pre>')
call writeln(html,' Number of Pages: 'cnt'</pre>')
call writeln(html,'<ul><a name="bot"></a>')
call writeln(html,'<h'hs'><a href="#htm">html</a>')
call writeln(html,'<a href="file:///'stem'i.html">ima<>ges</a>')
call writeln(html,'<a href="file:///'stem'ts.html">tim<>esort</a>')
call writeln(html,'<a href="file:///'stem'g.html" >cac<>heg<>rep</h'hs'></a></ul></body>')
call close(html)
call gfxhead
'Type >>'stem'i.html t:logy.tmp'
call open(html,stem'i.html',a)
call writeln(html,cenl(0)'<h/'bs'><pre>')
call writeln(html,' Number of images: 'icnt'</pre>')
call writeln(html,'<ul><a name=bot></a></body>')
call writeln(html,'<a href="file:///'stem'.html"><h'hs'>html</a>')
call writeln(html,'<a href="#gfx">ima<>ges</a>')
call writeln(html,'<a href="file:///'stem'ts.html">tim<>esort</a>')
call writeln(html,'<a href="file:///'stem'g.html" >cac<>heg<>rep</h'hs'></a></ul>')
call close(html)
'Delete >nil: t:#?.tmp'
exit
stat:
if status then
do
if ofs.i == 'empty' then return ' 0 '
/* else This is dangerous to use! it discarded my cache!
do
'ram:httpfetch >t:cont.tmp 'ofn.i' from localhost:80 '
if rc ~= 10 then
do
if ~open(ctst,'t:cont.tmp',r) then call ferr('t:ocnt.tmp')
ad=readch(ctst,100)
call close(ctst)
if index(upper(ad),error) > 0 then return ' E '
else return ''
end
else return ' U '
end */
end
else return ''
cenl:
parse arg switch
if centdok then
do
if switch then return '<center>'
else return '</center>'
end
else return ''
tmod: /* DD-MMM-JJ HH:MM:SS -> JJMMDD HH to make it sortable and short */
return delstr(fd.i,1,7)||month(substr(fd.i,4,3))||substr(fd.i,1,2)' 'delstr(ft.i,3)
month: /* convert the month abbrev. into number */
parse arg mt
select
when mt == word(monthident,1) then x='01'
when mt == word(monthident,2) then x='02'
when mt == word(monthident,3) then x='03'
when mt == word(monthident,4) then x='04'
when mt == word(monthident,5) then x='05'
when mt == word(monthident,6) then x='06'
when mt == word(monthident,7) then x='07'
when mt == word(monthident,8) then x='08'
when mt == word(monthident,9) then x='09'
when mt == word(monthident,10) then x='10'
when mt == word(monthident,11) then x='11'
when mt == word(monthident,12) then x='12'
otherwise nop
end
return x
str: procedure
parse arg t
if index(t,'http://') > 0 then t=delstr(t,1,7)
return t
grep:
if ~exists(stem'.html') then call ferr(stem'.html')
if ~exists(stem'i.html') then call ferr(stem'i.html')
if ~open(html,stem'g.html',w) then call ferr(stem'g.html')
call writeln(html,'<html><head><title>httpproxy index 'time(n)' 'date(e)'</TITLE></HEAD><BODY>')
call writeln(html,'<ul><a href=file:///'stem'.html><h'hs'>html</a>')
call writeln(html,'<a href="file:///'stem'ts.html">timeso<>rt</a>')
call writeln(html,'<a href=file:///'stem'i.html>images</h'hs'></a></ul><h'bs'>'cenl(1))
call close(html)
'Search >>'stem'g.html 'stem'.html 'pat' 'nonum
'Search >>'stem'g.html 'stem'i.html 'pat' 'nonum
'Echo >>'stem'g.html "'cenl(0)'<h/'bs'></body>"'
exit
ferr:
parse arg fname
say "Can't open: "fname
exit
htmlhead: /* html page */
if ~open(html,stem'.html',w) then call ferr(stem'.html')
call writeln(html,'<HTML><HEAD><TITLE>httpproxy in<>dex - html 'time(n)' 'date(e)'</TITLE></HEAD><BODY>')
call writeln(html,'<ul><a name='d2c(34)'htm'd2c(34)'><h'hs'>html</a>')
call writeln(html,'<a href="file:///'stem'i.html">ima<>ges</a>')
call writeln(html,'<a href="file:///'stem'ts.html">ti<>meso<>rt</a>')
call writeln(html,'<a href="file:///'stem'g.html" >ca<>cheg<>rep</a>')
call writeln(html,'<a href="#bot">bottom</a></h'hs'></ul><h'bs'>'cenl(1))
call close(html)
return
gfxhead: /* images page */
if ~open(html,stem'i.html',w) then call ferr(stem'.html')
call writeln(html,'<HTML><HEAD><TITLE>httpproxy index - ima<>ges 'time(n)' 'date(e)'</TITLE></HEAD><BODY>')
call writeln(html,'<ul><a name='d2c(34)'gfx'd2c(34)'><h'hs'>ima<>ges</a>')
call writeln(html,'<a href="file:///'stem'.html">html</a>')
call writeln(html,'<a href="file:///'stem'ts.html">ti<>meso<>rt</a>')
call writeln(html,'<a href="file:///'stem'g.html" >ca<>chegr<>ep</a>')
call writeln(html,'<a href="#bot">bot<>tom</a></h'hs'></ul><h'bs'>'cenl(1))
call close(html)
return
tsortpage: /* time-sorted page */
if ~open(html,stem'ts.html',w) then call ferr(stem'ts.html')
call writeln(html,'<HTML><HEAD><TITLE>httpproxy index - html timesort 'time(n)' 'date(e)'</TITLE></HEAD><BODY>')
call writeln(html,'<ul><a name='d2c(34)'top'd2c(34)'><h'hs'>tim<>es<>ort</a>')
call writeln(html,'<a href="file:///'stem'.html">html</a>')
call writeln(html,'<a href="file:///'stem'i.html">ima<>ges</a>')
call writeln(html,'<a href="#bot">bottom</a>')
call writeln(html,'<a href="file:///'stem'g.html">cac<>hegr<>ep</h'hs'></a></ul><h'bs'>'cenl(1))
tscnt=0
if ~readfile('t:time.tmp',fnt) then call ferr('t:time.tmp')
tsc=fnt.0 /* reverse the timesort tmp to get the */
do i=1 to fnt.0 /* last request on top */
call writeln(html,fnt.tsc)
tsc=tsc-1
end
call writeln(html,cenl(0)'<ul><a name="bot"></a>')
call writeln(html,'<h'hs'><a href="#top">top</a>')
call writeln(html,'<a href="file:///'stem'.html">html</a>')
call writeln(html,'<a href="file:///'stem'i.html">images</a>')
call writeln(html,'<a href="file:///'stem'ts.html">timesort</a>')
call writeln(html,'<a href="file:///'stem'g.html" >cachegrep</h'hs'></a></ul></body>')
call close(html)
return
getcont: /* Parse chachedir tree */
debug=0;cnt=1;stage=0
path=cachedir'http'
call open(log,'ram:log',w)
'List >t:cdir.tmp lformat "%p%n %d %t %b" dates 'path
if ~readlines('t:cdir.tmp',,,'%s %s %s %s','fn fd ft fs') then call ferr('t:cdir.tmp')
do forever
stage=stage+1
if debug then
do
say;say 'Processing Stage: 'stage;say
say copies(#,50)
say copies(#,16)' ident files 'copies(#,21)
say copies(#,50)
say;say 'Number of items: 'fn.0
end
else call writech(stdout,'/')
nextdir=0
do i=1 to fn.0
/* Processing of hash Files */
if index(fn.i,'@dirurl') > 0 | index(filepart(fn.i),'@@') > 0 | index(filepart(fn.i),'@!') > 0 then
do
if index(fn.i,'@dirurl') > 0 then
do
call open(fhandle,fn.i,r)
htpath=readln(fhandle)
call close(fhandle)
end
else
do
if index(filepart(fn.i),'@!') > 0 then
do
if fs.i == 'Dir' then /* if directory, queue to list */
do
nextdir=nextdir+1
q.nextdir=fn.i
end
else
do
if ~open(fh,pathpart(fn.i)'/'insert(@,delstr(filepart(fn.i),2,1),1),r) then call ferr(pathpart(fn.i)'/'insert(@,delstr(filepart(fn.i),2,1),1))
numfiles=numfiles+1
ofp.numfiles=pathpart(fn.i)'/'insert(@,delstr(filepart(fn.i),2,1),1)
time.numfiles=tmod()
ofn.numfiles=xport(readln(fh)||' 'striport);call close fh
ofs.numfiles=fs.i
if debug then do;say pathpart(fn.i)'/'insert(@,delstr(filepart(fn.i),2,1),1)' 'fs.i;end
end
end
end
end
else
do
if fs.i == 'Dir' then /* if directory, queue to list */
do
nextdir=nextdir+1
q.nextdir=fn.i
end
else
do
call addout
ofn.numfiles=ctourl(fn.i' 'striport' 'htpath)
if debug then do;say left(fn.i,65)' 'fs.i;say 'htPath: 'htpath;end
end
end
end
if nextdir == 0 then break
if debug then
do
say;say 'dirs to list';say
do k=1 to nextdir
say q.k
end
say;say copies(#,16)' list 'copies(#,26);say
end
flcnt=0
do i=1 to nextdir
'List >t:cdir.tmp lformat "%p%n %d %t %b" dates "'q.i'/#?"'
if ~readlines('t:cdir.tmp',,,'%s %s %s %s','tfn tfd tft tfs') then call ferr('t:cdir.tmp')
dul=lsearch('*@dirurl',tfn,,,p) /* @dirurl to start of list */
if dul > 1 then
do
tmp.1 = tfn.dul ; tfn.dul = tfn.1 ; tfn.1 = tmp.1
tmp.2 = tfd.dul ; tfd.dul = tfd.1 ; tfd.1 = tmp.2
tmp.3 = tft.dul ; tft.dul = tft.1 ; tft.1 = tmp.3
tmp.4 = tfs.dul ; tfs.dul = tfs.1 ; tfs.1 = tmp.4
end
if tfn.0 > 0 then
do
acnt=1
if debug then do;say;say 'Dir contents of: 'q.i;say;end
do j=flcnt to flcnt+tfn.0-1
flcnt=flcnt+1
fn.flcnt = tfn.acnt /* filename */
fd.flcnt = tfd.acnt /* filedate */
ft.flcnt = tft.acnt /* filetime */
fs.flcnt = tfs.acnt /* filezize */
if debug then say 'Fnr: 'flcnt' 'fn.flcnt' 'fs.flcnt
acnt=acnt+1
end
end
end
fn.0=flcnt
if debug then say
end
return
addout: /* Add an item to the output-list */
numfiles=numfiles+1
ofp.numfiles=fn.i
time.numfiles=tmod()
ofs.numfiles=fs.i
return
ctourl: procedure expose port /* Convert the filepath into URL */
parse arg t' 's' 'p
t=p||filepart(t)
if substr(t,length(t)) == @ then t=substr(t,1,length(t)-1)
if port == substr(t, index(t,':',8)+1, index(t,'/',8)-index(t,':',8)-1) then
if s then t=delstr(t, index(t,':',8),index(t,'/',8)-index(t,':',8)) /* strip port nr */
return t
xport: procedure expose port
parse arg t' 's
if port == substr(t, index(t,':',8)+1, index(t,'/',8)-index(t,':',8)-1) then
if s then t=delstr(t, index(t,':',8), index(t,'/',8)-index(t,':',8)) /* strip port nr */
return t
/* eof */